const app = getApp()
let qCloud = require("../../index.js");

Page({
    /** 页面的初始数据 */
    data: {
        imgPath: qCloud.config.STATIC_IMAGE_PATH,
        produceTaskList:[],
        goodsList:[]
    },

    /** 生命周期函数--监听页面加载 */
    onLoad: function (options) {

    },

    /** 搜索内容*/
    searchValueInput: function (e){
        let params = {
            searchValue: e.detail.value
        }
        this.search(params);
    },

    bindGoodsGoTo: function (e) {
        wx.navigateTo({
            url: e.currentTarget.dataset.url
        })
    },

    // 跳转-生产任务详情页面
    todetailTap(e) {
        wx.navigateTo({
            url: e.currentTarget.dataset.url
        });
    },

    // 搜索条件
    search: function (params){
        let self = this;
        app.fetchApis(self, qCloud.api.common_search, params, "GET", function (e) {
            let result = e.data;
            if (result.code == 200) {
                let produceTaskList = [];
                for (let i = 0; i < result.produceTaskList.produceTaskList.length; i++) {
                    let produceTaskInfo = result.produceTaskList.produceTaskList[i];
                    let produceTask = {
                        produceTaskId: produceTaskInfo.produceTaskId, // 生产任务ID
                        produceTaskCode: produceTaskInfo.produceTaskCode, // 生产任务编号
                        produceTaskBedNo: produceTaskInfo.produceTaskBedNo, // 生产任务床号
                        produceTaskName: produceTaskInfo.produceTaskName, // 生产任务名称
                        produceTotal: produceTaskInfo.produceTotal, // 生产数量
                        completedPercentage: produceTaskInfo.completedPercentage, // 完成百分比
                        startTime: produceTaskInfo.startTime, // 开始时间
                        deliveryTime: produceTaskInfo.deliveryTime, // 交货时间
                    };
                    produceTaskList.push(produceTask);
                }
                self.setData({
                    produceTaskList: produceTaskList
                });


                let goodsList = [];
                for (let i = 0; i < result.goodsList.goodsList.length; i++) {
                    let goodsInfo = result.goodsList.goodsList[i];
                    let goods = {
                        goodsId: goodsInfo.goodsId,
                        goodsName: goodsInfo.goodsName,
                        goodsTotalNumber: goodsInfo.goodsTotalNumber,
                        warehouseName: goodsInfo.warehouseName
                    };
                    goodsList.push(goods);
                }

                self.setData({
                    goodsList: goodsList,
                });
            }
        });
    }

});
